package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.RoleDto;
import com.zzyl.service.RoleService;
import com.zzyl.vo.RoleVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.zzyl.base.ResponseResult.success;

@RestController
@Api(tags ="角色管理")
@RequestMapping("/role")
public class RoleController {
    @Autowired
    private RoleService roleService;
    @PostMapping("/page/{pageNum}/{pageSize}")
    public ResponseResult<PageResponse<RoleVo>> queryPage(@PathVariable Integer pageNum, @PathVariable Integer pageSize, @RequestBody RoleDto roleDto) {
        PageResponse<RoleVo> page = roleService.queryPage(pageNum, pageSize, roleDto);
        return success(page);
    }
    @PutMapping
    @ApiOperation("角色添加")
    public ResponseResult add(@RequestBody RoleDto roleDto) {
        roleService.add(roleDto);
        return success();
    }

    @GetMapping("/find-checked-resources/{roleId}")
    @ApiOperation("根据角色id查询已选中的资源")
    public ResponseResult<List<String>> findCheckedResources(@PathVariable Long roleId) {
        List<String> data = roleService.findCheckedResources(roleId);
        return success(data);
    }

    @PatchMapping
    @ApiOperation("角色修改、启用禁用、菜单权限修改")
    public ResponseResult update(@RequestBody RoleDto roleDto) {
        roleService.update(roleDto);
        return success();
    }
}
